package org.road0329.dlt698.axdr;

import org.road0329.dlt698.ReverseByteArrayInputStream;
import org.road0329.dlt698.ReverseByteArrayOutputStream;
import org.road0329.dlt698.asn1.axdr.AxdrEnum;
import org.road0329.dlt698.asn1.axdr.AxdrType;

public class ReportNotification  extends AxdrType {
    private byte[] dataCode = null;
    private Choice choice = ReportNotification.Choice._ERR_NONE_SELECTED;

    private ReportNotificationRecordList reportNotificationRecordList = null;

    public byte[] getDataCode() {
        return dataCode;
    }

    public Choice getChoice() {
        return choice;
    }

    public ReportNotificationRecordList getReportNotificationRecordList() {
        return reportNotificationRecordList;
    }

    @Override
    public int encode(ReverseByteArrayOutputStream output) throws Exception {
        if (this.dataCode != null) {
            for (int i = this.dataCode.length - 1; i >= 0; i--) {
                output.write(this.dataCode[i]);
            }
            return this.dataCode.length;
        }
        if (this.choice == Choice._ERR_NONE_SELECTED) {
            throw new Exception("Error encoding AxdrChoice: No item in choice was selected.");
        }
        int codeLength = 0;
        if (this.choice == Choice.REPORT_NOTIFICATION_RECORD_LIST) {
            codeLength += this.reportNotificationRecordList.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(7);
            codeLength += c.encode(output);
            return codeLength;
        }
        throw new Exception("Error encoding AxdrChoice: No item in choice was encoded.");
    }

    @Override
    public int decode(ReverseByteArrayInputStream input) throws Exception {
        int codeLength = 0;
        AxdrEnum choosen = new AxdrEnum();
        codeLength += choosen.decode(input);
        this.resetChoices();
        this.choice = Choice.getEnumByValue((int)choosen.getValue());
        if (this.choice == Choice.REPORT_NOTIFICATION_RECORD_LIST) {
            this.reportNotificationRecordList = new ReportNotificationRecordList();
            codeLength += this.reportNotificationRecordList.decode(input);
            return codeLength;
        }
        throw new Exception("Error decoding AxdrChoice: Identifier matched to no item.");
    }

    public Choice getChoiceIndex() {
        return this.choice;
    }

    public void resetChoices() {
        this.choice = Choice._ERR_NONE_SELECTED;
        this.reportNotificationRecordList = null;
    }

    public enum Choice {
        _ERR_NONE_SELECTED(-1),
        REPORT_NOTIFICATION_LIST(1),
        REPORT_NOTIFICATION_RECORD_LIST(2),
        REPORT_NOTIFICATION_TRANS_DATA(3),
        REPORT_REQUEST_CLIENT_SERVICE(4),
        REPORT_NOTIFICATION_SIMPLIFY_RECORD(5);

        private final int value;

        private Choice(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public static Choice getEnumByValue(int value) {
            for (Choice item : Choice.values()) {
                if (value == item.getValue()) {
                    return item;
                }
            }
            return null;
        }
    }

}
